package com.wyf.android.advance.rvvp

import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.wyf.android.advance.R
import com.wyf.android.baselib.util.inflate

class RVVP1Adapter() : ListAdapter<RVVPViewData, RVVP1Adapter.RVVP1ViewHolder>(RVVP1DiffUtil()) {

    open inner class RVVP1ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
        open fun bind() {

        }
    }

    inner class TopViewHolder(v: View) : RVVP1ViewHolder(v) {
        override fun bind() {
            val topViewData = getItem(adapterPosition) as TopViewData
            (itemView as TextView).text = topViewData.t + "--" + adapterPosition
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RVVP1ViewHolder {
        return TopViewHolder(parent.inflate(R.layout.item_rvvp_top))
    }

    override fun onBindViewHolder(holder: RVVP1ViewHolder, position: Int) {
        holder.bind()
    }
}

class RVVP1DiffUtil : DiffUtil.ItemCallback<RVVPViewData>() {
    override fun areItemsTheSame(oldItem: RVVPViewData, newItem: RVVPViewData): Boolean {
        return if (oldItem is TopViewData && newItem is TopViewData) {
            oldItem == newItem
        } else {
            true
        }
    }

    override fun areContentsTheSame(oldItem: RVVPViewData, newItem: RVVPViewData): Boolean {
        return oldItem == newItem
    }
}